import request from '@/utils/request'
import type {
  TradeMarkResponseData,
  TradeMark,
} from '@/api/product/trademark/type'

enum API {
  // 品牌分页查询
  TRADEMARK_URL = '/admin/product/baseTrademark',
  // 添加品牌
  ADD_TRADEMARK_URL = '/admin/product/baseTrademark/save',
  // 修改品牌
  UPDATE_TRADEMARK_URL = '/admin/product/baseTrademark/update',
  // 根据品牌ID删除品牌
  DELETE_TRADEMARK_URL = '/admin/product/baseTrademark/remove',
}

// 获取第几页数据
export const reqHasTrademark = (page: number, limit: number) =>
  request.get<any, TradeMarkResponseData>(
    `${API.TRADEMARK_URL}/${page}/${limit}`,
  )

// 新增或更新品牌
export const reqAddOrUpdateTrademark = (data: TradeMark) => {
  // 修改已有品牌的数据
  if (data.id) {
    return request.put<any, any>(API.UPDATE_TRADEMARK_URL, data)
  } else {
    // 新增品牌
    return request.post<any, any>(API.ADD_TRADEMARK_URL, data)
  }
}

// 根据品牌ID删除品牌
export const reqDeleteTradeMark = (id: number) =>
  request.delete(`${API.DELETE_TRADEMARK_URL}/${id}`)
